package com.kotlin.flong.coroutines

import kotlinx.coroutines.*

/**
 * @Author:liangjl
 * @Date: 2020/7/7-16:23
 * @Eamil:jilongliang@sina.com
 * @Description:
 */

fun main()= runBlocking {

    println("获取job1返回值")
    //返回Deferred
    var  job1 = GlobalScope.async{ job1()}
    //执行完之后才可以获取数据，await是属于suspend挂起函数
    var await1 = job1.await()
    println(await1)

    var  job2 = GlobalScope.async{ job2()}
    //执行完之后才可以获取数据，await是属于suspend挂起函数
    var await2 = job2.await()
    println(await2)

}
suspend fun job1(): String {
    println("开始执行job1")
    delay(1000L)
    println("执行job1")
    return "job1"
}
suspend fun job2(): String {
    println("开始执行job2")
    delay(1000L)
    println("执行job2")
    return "job2"
}